package phonedate;

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

/** 
* @Description: 序列化mapper类
 *LongWritable，Text ==>   Map的输入        <偏移量，手机号>
 * Text，FlowBean  ====>   Map的输出：<手机号，流量上传下载总和>
 *
* @Author: Qiang.Ye
* @Date: 2019/5/26
*/ 
public class FlowCountMapper extends Mapper<LongWritable, Text,Text, FlowBean> {

    Text k  = new Text();
    FlowBean v = new FlowBean();

    @Override
    protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
        //1.获取每一行的数据
        String line = value.toString();

        //2.切割字段
        //1363157985066 	13726230503	00-FD-07-A4-72-B8:CMCC	120.196.100.82	i02.c.aliimg.com		24	27	2481	24681	200
        String[] filds = line.split("\t");
        String phone = filds[1];
        long upflow = Long.parseLong(filds[filds.length - 3]);
        long downflow = Long.parseLong(filds[filds.length - 2]);

        k.set(phone);

        context.write(k,new FlowBean(upflow,downflow));

    }
}
